
module.exports = app => {

    return class HomeworkController extends app.Controller {
        async index() {
            let today = await this.service.homework.today();
            await this.ctx.render('study/homework/index.js', {
                today
            });
        }

        async practice() {
            let params = this.ctx.request.query;
            let id = params.id;
            let questions = await this.service.study.one({ id });
            await this.ctx.render('study/homework/practice/index.js', {
                questions,
                id
            });
        }

        async today() {
            let params = await this.ctx.request.query;
            let data = await this.service.homework.today(params);
            this.success(data);
        }

        async history() {
            let params = await this.ctx.request.query;
            let data = await this.service.homework.history(params);
            this.success(data);
        }

        async unfinished() {
            let params = await this.ctx.request.query;
            let data = await this.service.homework.unfinished(params);
            this.success(data);
        }


        async detail() {
            let params = this.ctx.request.query;
            let questions = await this.service.exercise.detail(params);
            await this.ctx.render('study/homework/practice/detail/index.js', {
                questions,
                params
            });
        }

        async result() {
            let id = this.ctx.request.query.id;
            let report = await this.service.study.report({
                id
            });
            await this.ctx.render('study/homework/practice/result/index.js', {
                report
            });
        }

        /**
         * 练习提交
         * @returns {Promise<void>}
         */
        async submit() {
            let params = this.ctx.request.body;
            await this.service.study.submit(params);
            this.success();
        }


    };
};
